52

Beginner’s Guide to Code Algorithms

52

STEP 13 continued

              For kb =​ 1 To 3

                nb =​ Int((i -​ 1) /​ 3) * 3 +​ kb

                For lb =​ 1 To 3

                  pb =​ Int((j -​ 1) /​ 3) * 3 +​ lb

                  If (nb =​ n And pb =​ p) Or (nb =​ na And pb =​ pa) Then

                  Else

                    Call addtocantbelist(Mid(putnumberpresent(n, p), 1, 1), nb, pb)

                    Call addtocantbelist(Mid(putnumberpresent(n, p), 2, 1), nb, pb)

                  End If

                Next lb

                Next kb

                la =​ 4 ‘Exit For

                ka =​ 4 ‘Exit For

                l =​ 4 ‘Exit For

                k =​ 4 ‘Exit For

                End If

              End If

            Next la

          Next ka

        Next l

      Next k

    Next j

Next ii

This algorithm can be extended to work for not only a “love-​locked pair” but also

a trio (3), quartet (4), quintet (5), or sextet (6). The instructions become more compli­

cated and the likelihood of finding such a case is progressively lower, as you advance

in your goal of uncovering all the blank cells.

One other variation of this theme involves a slight redefinition of the love-​locked

pair. In the previous method, we saw that the candidates for the “love-​locked pair”

are those that have exactly the same two candidates in the same cell, row, or 3 by 3

grid. The same is true if exactly the same two numbers are the sole candidates for

two different cells in the same row, column, or 3 by 3 grid. This is a slightly different

situation where each “love-​locked pair” cell can have more than two candidates. See

example in Figure 3.6:

7

5

6

2

9

3

4 4

(2,5,6)

9

1

3

7

8

1

4

3

(5,7,9)

2

4

6

1

8

9

(2,5,6)

1

3

4

8

7

7

6

2

9

5

8

COLUMN 1

2 3 4 5 6 7 8 9

9 8 7 6 5 4 3 2 1

ROW

FIGURE 3.6  Second love-​locked pair.